package com.qf.service.impl;

import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.service.UserService;

import java.util.List;

/**
 * @version v1.0.0
 * @Description:
 * @author: 赵英杰
 * @date: 2022.02.10
 * @since 1.0
 */
public class UserServiceImpl implements UserService {
    private UserDao userDao;

    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> findUserList() {
        return userDao.queryAll();
    }

    /**
     * 从 from 转到  to  ， 转2块
     *
     * @param from
     * @param to
     */
    @Override
    public void transfer(String from, String to) {

        User fromUser = userDao.findByUsername(from);
        User toUser = userDao.findByUsername(to);

        //更新余额
        fromUser.setMoney(fromUser.getMoney() - 2);
        toUser.setMoney(toUser.getMoney() + 2);
        //更新数据库
        userDao.update(fromUser);

        System.out.println(1 / 0);


        userDao.update(toUser);
    }
}
